/**
 * Copyright (C) 2011 The Android Open Source Project 
 * Emial : guoyil199@163.com
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at 
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0 
 * 
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 * See the License for the specific language governing permissions and 
 * limitations under the License. 
 */ 
package com.scroll;

import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.example.app.R;
import com.scroll.SuspensionScrollView.OnScrollListener;


/**
 * @author Administrator
 * @Email guoyil199@163.com
 * @version V1.0
 * @Date 2015年5月14日 下午1:33:56
 * @Title <pre>todo</pre>
 * @Description <pre>todo</pre>
 */

public class TestSuspensionAct extends Activity implements OnScrollListener{
	private Button search_edit;
	private SuspensionScrollView myScrollView;
    private int searchLayoutTop;
    
    LinearLayout search01,search02;
    RelativeLayout rlayout;
    
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main_test_suspension);
		//初始化控件
		init();
	}

	private void init() {
		search_edit = (Button)findViewById(R.id.search_edit);
		myScrollView = (SuspensionScrollView)findViewById(R.id.myScrollView);
		search01 = (LinearLayout)findViewById(R.id.search01);
		search02 = (LinearLayout)findViewById(R.id.search02);
		rlayout = (RelativeLayout)findViewById(R.id.rlayout);
		myScrollView.setOnScrollListener(this);  
        
	}

	@Override
	public void onWindowFocusChanged(boolean hasFocus) {
		super.onWindowFocusChanged(hasFocus);    
        if(hasFocus){  
        	searchLayoutTop = rlayout.getBottom();//获取searchLayout的顶部位置
        }
	}

	//监听滚动Y值变化，通过addView和removeView来实现悬停效果
	@Override
	public void onScroll(int scrollY) {
		if(scrollY >= searchLayoutTop){  
			if (search_edit.getParent()!=search01) {
				search02.removeView(search_edit);
				search01.addView(search_edit);
			}
        }else{
        	if (search_edit.getParent()!=search02) {
        		search01.removeView(search_edit);
        		search02.addView(search_edit);
			}
        }
	}
}
